package com.课上案例练习.线程.线程安全.Lock锁;


import java.util.concurrent.locks.ReentrantLock;

/**
 * Lock锁
 *
 *
 *
 */
public class Test1 {
    public static void main(String[] args) {
             //创建锁对象
        ReentrantLock lock = new ReentrantLock();
        //线程一
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    //开启锁
                      lock.lock();
                    System.out.print("我");
                    System.out.print("想");
                    System.out.print("看");
                    System.out.print("看");
                    System.out.println();
                    lock.unlock();
                }
            }
        }).start();
        //线程二
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    lock.lock();
                    System.out.print("世");
                    System.out.print("界");
                    System.out.print("那");
                    System.out.print("么");
                    System.out.print("大");
                    System.out.println();
                    lock.unlock();
                }
            }
        }).start();
    }
}
